/**
 * 自定义指令
 */
import { authStore } from "@/store";
import type { DirectiveBinding } from "vue";

//权限指令
const hasPermission = {
    mounted(el: HTMLButtonElement, binding: DirectiveBinding) {
        //1.获取绑定的权限值
        const permission = binding.value;
        if (permission === "*") {
            return;
        }

        //2.从pinia里获取权限信息，然后根据路由获取标识集合
        const auth = authStore();
        const signList = auth.routerResourceList[location.pathname];

        //3.判断用户是否拥有权限
        if (signList?.findIndex((sign: string) => sign == permission) < 0) {
            el.remove();
        }
    },
};

//暴露
export { hasPermission };
